<script type="text/javascript" src="{baseUrl}/public/js/jquery.md5.js"></script>

<div class="profiltop"><?php echo $this->translate( 'my_account' ) ?></div>
<?php if( !$this->userData ) { ?>

<?php echo $this->inlineScript()->setScript('
	$(document).ready(function(){
		$.validator.setDefaults({
			submitHandler: function(e) { 
				var fields = $(e).find( "input.style1" );
				
				$("#login-form5").animate({
					opacity: 0
				});
				
				$.post(
					baseUrl + "/index/login",
					{
						login : $( "#log_mail" ).val(),
						password : $.md5( $("#log_pass" ).val() ),
						json : true
					},
					function( resp ){
						if( resp.status ) {
							window.location.reload();
						} else {
							alert( "' . $this->translate( 'error_login' ) . '" );
							$("#login-form5").animate({
								opacity: 1
							});
						}
					},
					"json"
				);
			}
		});
	
		$("#form1log").validate({
			rules: {
				email : {
					required: true,
					email: true
				},
				pass : {
					required: true,
					minlength: 2
				}
			},
			messages: {
				email : "' . $this->translate( 'error_email' ) . '",
				pass : "'. $this->translate( 'error_password' ) .'"
			}
		});
	});
	') ?>
	
<div class="box nomtop " id="login-form5">

<h1><?php echo $this->translate( 'shop_bon_logowanie' ); ?></h1>

<form id="form1log" method="post" action="">
<table class="tab">
	<tr>
		<td class="aright"><?php echo $this->translate( 'shop_bon_login' ); ?>:</td>
		<td><input type="text" name="email" id="log_mail" value="" class="type5"></td>
	</tr>
	<tr>
		<td class="aright"><?php echo $this->translate( 'shop_bon_pass' ); ?>:</td>
		<td><input type="password" name="password" id="log_pass" value="" class="type5"></td>
	</tr>
</table>
</form>

<div class="line" style="margin:10px 0"></div>

<div class="acenter">
<a href="javascript:;" class="button" onclick="$('#form1log').submit()"><?php echo $this->translate( 'shop_bon_logowanie' ); ?></a>
</div>

<div class="acenter" style="margin-top:20px">
<p>

	<a href="{baseUrl}/index/newaccount" class="orange"><?php echo $this->translate( 'basket_newaccount' ) ?></a> <span style="margin:0 10px">/</span> <a href="{baseUrl}/index/remindpass"><?php echo $this->translate( 'basket_remind' ) ?></a></p>
</div>

<div class="end"></div>

	
</div>
<?php } else { ?>
<div class="box boxprofile">
	
	<div class="menu">
		<div class="acenter">
			<a href="{baseUrl}/shop/account" class="button prodmenu"><?php echo $this->translate( 'my_details' ) ?></a>
			<a href="{baseUrl}/shop/orders" class="button prodmenu"><?php echo $this->translate( 'my_orders' ) ?></a>
			<a href="{baseUrl}/shop/observed" class="button prodmenu buttonactive"><?php echo $this->translate( 'my_observed' ) ?></a>
			<a href="{baseUrl}/shop/vouchers" class="button prodmenu"><?php echo $this->translate( 'my_vouchers' ) ?></a>
		</div>
	</div>
	
	
	<form method="post" action="{baseUrl}/shop/basket/observed/1" id="obs_form">
		<?php foreach( $this->list as $value ) { 
			$free = $this->Findfree( $value['Products']['Dimension'] );
		?>
		<div class="boxprod">
    		<div class="photo"><img src="<?php echo $this->File(  $value['Products']['Galeries']['Photos']->toArray(), 100 ) ?>" alt=""></div>
    		<p class="name"><a href=""><?php echo $value['Products']['name_' . $this->locale ]; ?></a></p>
    		<p class="price"><?php echo $this->Price( $value['Products'], $free, $this->locale, true ) ?></p>
            <table class="prodoption">
            	<tr>
            		<td><?php echo $this->translate( 'capacity' ); ?>:</td>
            		<td class="aleft">
            			<select id="dimension_<?php echo  $value['Products']['p_id']; ?>_<?php echo  $value['w_id']; ?>" name="dimension[<?php echo $value['Products']['p_id']; ?>]">
            			<?php 
						$i = 0; 
						foreach( $value['Products']['Dimension'] as $dim ) { 
							if( $dim['stock'] > 0 ) {
						?>
								<option value="<?php echo $dim['d_id']; ?>"><?php echo $dim['name'] ?></option>
							<?php
							} 
							$i++; 
						} 
						?>
            			</select>
            			<?php echo $this->inlineScript()->setScript('
						var selectAll;
						var deleteObserved;
						
						$(document).ready(function(){
						
							
							deleteObserved = function() {
								var arr = [];	
							
								var list = $("#obs_form").find( "input[type=checkbox]:checked" );
								for( var i = 0, len = list.length; i < len; i++ ) {
									arr.push( $( list[i] ).val() );
								}
								console.log(list);
								if( arr.length > 0 ) {

									$.post(
										baseUrl + "/shop/observed",
										{ elem : arr },
										function( resp ) {
											window.location.reload();
										}
									);
								}
							};
							
							var stock'.$value['w_id'].' = ' . $value['Products']['Dimension'][0]['stock'] . ';
							
							
							var stockInput = $( "#stock' . $value['w_id'] . '" );
							var addtobasket = $( "#addtobasket" );
							var items = 0;
							
							$( "#leftstock' . $value['w_id'] . '" ).click(function(){
							
								if(stock'.$value['w_id'].'!=0)
								{
    								if( stockInput.val() > 1 ) {
    									items = parseInt( stockInput.val() ) - parseInt( 1 );
    									stockInput.val( items );
    								}
								}
							});
							
							$( "#rightstock' . $value['w_id'] . '" ).click(function(){

								if(stock'.$value['w_id'].'!=0)
								{
    								if( stockInput.val() && stock'.$value['w_id'].'>stockInput.val() ) {
    									items = parseInt( stockInput.val() ) + parseInt( 1 );
    									stockInput.val( items );
    								}
								}
							});
							
							
                    		stockInput.keyup(function () { 	
                        		if(stock'.$value['w_id'].'!=0)
                        		{
                        			if(parseInt(this.value)<=parseInt(stock'.$value['w_id'].'))
                        			{
                        			 this.value = this.value.replace(/[^0-9\.]/g,"");
                        			}
                        			else
                        			{
                        				if(this.value!="")
                        				{
                        				 this.value = stock'.$value['w_id'].';
                        				}
                        			}
                        		}
                        		else
                        		{
                        			stockInput.val(0);
                        		}
                        		
 								addtobasket.attr( "href", addtobasket.attr( "href" ).replace( /items\/[0-9]{1,}/, "items/" + this.value  ) );
       
                            });
							
                            if(stock'.$value['w_id'].'==0)
                            {
                                stockInput.val(0);
    							addtobasket.attr( "href", addtobasket.attr( "href" ).replace( /items\/[0-9]{1,}/, "items/0"  ) );
                            }
                            
							
						})'); ?>
            		</td>
            		<td><?php echo $this->translate( 'product_number' ); ?>:</td>
            		<td class="aleft">
            			<input type="text" id="stock<?php echo $value['w_id'] ?>" name="stock[<?php echo $value['Products']['p_id']; ?>]" class="ilinput acenter style1 icount" style="height:23px; line-height:23px; padding:0 6px; *position:relative; *left:-2px; *top:-1px" value="1">
            		</td>
            	</tr>
            </table>
    		<p class="checkbox"><input type="checkbox" name="add[<?php echo $value['Products']['p_id']; ?>]" value="<?php echo $value['Products']['p_id']; ?>" id="c<?php echo $value['w_id'] ?>"><label for="c<?php echo $value['w_id'] ?>"></label></p>
    	</div>
    	
    	
		<?php } ?>
		

		
		<script type="text/javascript">

	$(document).ready(function(){

		$('#selectall').click(function(){

			if($('#form1 input[type="checkbox"]').is(':checked')){
					$('#obs_form input[type="checkbox"]').attr('checked',false);
				}else{
					$('#obs_form input[type="checkbox"]').attr('checked',true);	
			}
		});
		
	});

	</script>
<div style="width:605px; margin:0 auto">
		<p id="selectall" class="aright bold orange sh" style="margin:15px auto 10px auto"><?php echo $this->translate( 'select_all' ) ?></p>
		
    	<table class="selected">
    		<tr>
    			<td><?php echo $this->translate( 'selected' ) ?>:</td>
    			<td><a href="javascript:;" onclick="deleteObserved()" class="button"><?php echo $this->translate( 'selected_delete' ) ?></a></td>
    			<td style="padding-right:0"><a href="javascript:;" onclick="$('#obs_form').submit()" class="button"><?php echo $this->translate( 'selected_add_to_basket' ) ?></a></td>
    		</tr>
    	</table>
	</div>
	
	<div class="clr"></div>
	<div class="end"></div>
	
</div>


		<?php //echo $this->render('global/pager_service_small.phtml'); ?>
	

	
<?php } ?>